<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>活动举办列表</title>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <script src="../../demo/demo.css" type="text/javascript"></script>
    <style type="text/css">
      html, body{
          margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
      }    
      </style>
  </head>
  <body>
    <div style="width: 100%">
      <div class="mini-toolbar" style="border-bottom: 0; padding: 0px">
        <table style="width: 100%">
          <tr>
            <td style="width: 100%">
              <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
      <div
        id="datagrid1"
        class="mini-datagrid"
        style="width: 100%; height: 100%"
        url="/club/activitylistaction?method=queryActivityInfo"
        idField="activityId"
        multiSelect="true"
      >
        <div property="columns">
          <div type="checkcolumn"></div>
            <div type="indexcolumn">序号</div>       
          <div
            field="activityId"
            width="120"
            headerAlign="center" align="center"
          >
            活动编号
          </div>
          <div field="activityName" width="120" headerAlign="center" align="center">
            活动名称
          </div>
          <div field="clubName" width="120" headerAlign="center" align="center">
            俱乐部名称
          </div>
          <div field="publicTime" width="120" headerAlign="center" align="center">
            举办时间
          </div>
          <div field="publicPlace" width="120" headerAlign="center" align="center" renderer="onPlaceRenderer">举办地点
          </div>
          <div field="isFree" width="50" headerAlign="center" align="center"  renderer="onFreeRenderer">
            免门票
          </div>
          <div field="partNum" width="50" headerAlign="center" align="center">
            报名人数
          </div>
          <div field="optionButton" width="40" headerAlign="center" align="center" renderer="onOptionRenderer">
            操作
          </div>
          
        </div>
      </div>
    </div>

    <script type="text/javascript">
      mini.parse();
      

      var grid = mini.get("datagrid1");
      grid.load();
      // grid.sortBy("createtime", "desc");
      
      var placeRender = null;
      var freeRender = null;
      // 获取地区映射
      placeReflect()
      // 获取是否免费映射
      freeReflect()


      ////////////////控件渲染//////////////////
      function onOptionRenderer(e) {
        return '<a class="mini-button" onclick="deleteInfo(\''+e.row.activityId+'\')">&nbsp;&nbsp;删除&nbsp;&nbsp;</a> &nbsp;'
      }

      // 渲染地区
      function onPlaceRenderer(e) {
        for (var i = 0, l = placeRender.length; i < l; i++) {
            var g = placeRender[i];
            if (g.id == e.value) return g.text;
        }
        return "";
      }

      // 渲染是否免门票
      function onFreeRenderer(e) {
        for (var i = 0, l = freeRender.length; i < l; i++) {
            var g = freeRender[i];
            if (g.id == e.value) return g.text;
        }
        return "";
      }



      ////////////////ajax/////////////////////////
      // 获取地区映射
      function placeReflect() {
        $.ajax({
            url: bootPATH + "../data/place.txt",
            type: 'GET',
            cache: false,
            success: function (text) {
              // 一定要转一下不然不是对象形式
              placeRender = mini.decode(text)
            },
            error: function () {
            }
        });
      }

      // 获取是否免费映射
      function freeReflect() {
        $.ajax({
            url: bootPATH + "../data/free.txt",
            type: 'GET',
            cache: false,
            success: function (text) {
              // 一定要转一下不然不是对象形式
              freeRender = mini.decode(text)
            },
            error: function () {
            }
        });
      }

      // 删除接口
      function deleteActivityInfoAjax(activityId) {
        $.ajax({
            url: "/club/activityeditaction?method=deleteActivityInfo&activityId=" + activityId,
            type: 'GET',
            cache: false,
            success: function (text) {
              mini.alert(text, '提示')
              grid.load()
            },
            error: function () {
            }
        });
      }

       

      /////////////////////////////////////////////

      function deleteInfo(activityId) {
        mini.confirm('确定要删除吗？', '提示', function(action) {
          if (action == 'ok') {
            deleteActivityInfoAjax(activityId)
          }
        })
      }

      function add() {
        mini.open({
          url: bootPATH + "../pages/activityinfo/activityadd.html",
          title: "新增活动信息",
          width: 600,
          height: 400,
          onload: function () {
            // var iframe = this.getIFrameEl();
            // var data = { action: "new" };
            // iframe.contentWindow.SetData(data);
          },
          ondestroy: function (action) {
            grid.reload();
          },
        });
      }

    </script>
  </body>
</html>
